<div id="sensor_select">
<div>
<form method="post">
<label for="sensor">Sensor:</label>
<select name="sensor">
<?php

	// Get all of the active sensors
	$sensors = get_active_sensors($database);

	// If there is a sensor value set from the form, then store it in the session var
	if(isset($_POST['sensor']))
	{
		$_SESSION['sensorID'] = $_POST['sensor'];
	}

	// Go through each sensor as an association between ID and name
	foreach($sensors as $id=>$name)
	{

		// If no sensor is set, set it to this one
		if(!isset($_SESSION['sensorID'])) {
			$_SESSION['sensorID'] = $id;
		}
		
		// Create drop box of all sensor names, and set the selected element to the currently selected sensor
		$output = '<option value="'.$id.'"';
		if(isset($_SESSION['sensorID']) && $_SESSION['sensorID'] == $id)
		{
			$output = $output.' selected="selected"';
		}
		if($name == "")
		{
				$output = $output.'> Unnamed : '.$id.'</option>';
		}
		else
		{
			$output = $output.'>'.$name.'</option>';
		}
		
		// Echo the create HTML
		echo $output;
	}
?>
</select>
<input class="submit" type="submit" value="Select" />
</form>
</div>
</div>
